package com.lsa.letcode.the15.the3sum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class The3SumTest {
	@Test
	public void test() {
		Solution s = new Solution();
		test(s,Arrays.asList(Arrays.asList(-6,2,4), Arrays.asList(-5,1,4), Arrays.asList(-5,2,3)),new int[]{-5, 3, 2, -6, 4, 2, -8, -9, 1});
		test(s, Arrays.asList(Arrays.asList(-1,-1,2),Arrays.asList(-1,0,1)), new int[]{-1, 0, 1, 2, -1, -4});
		test(s,Arrays.asList(Arrays.asList(-15,1,14), Arrays.asList(-15,2,13), Arrays.asList(-15,3,12), Arrays.asList(-15,4,11), Arrays.asList(-15,5,10), Arrays.asList(-15,6,9), Arrays.asList(-15,7,8), Arrays.asList(-14,0,14), Arrays.asList(-14,1,13), Arrays.asList(-14,2,12), Arrays.asList(-14,3,11), Arrays.asList(-14,4,10), Arrays.asList(-14,5,9), Arrays.asList(-14,6,8), Arrays.asList(-14,7,7), Arrays.asList(-13,-1,14), Arrays.asList(-13,0,13), Arrays.asList(-13,1,12), Arrays.asList(-13,2,11), Arrays.asList(-13,3,10), Arrays.asList(-13,4,9), Arrays.asList(-13,5,8), Arrays.asList(-13,6,7), Arrays.asList(-12,-2,14), Arrays.asList(-12,-1,13), Arrays.asList(-12,0,12), Arrays.asList(-12,1,11), Arrays.asList(-12,2,10), Arrays.asList(-12,3,9), Arrays.asList(-12,4,8), Arrays.asList(-12,5,7), Arrays.asList(-12,6,6), Arrays.asList(-11,-3,14), Arrays.asList(-11,-2,13), Arrays.asList(-11,-1,12), Arrays.asList(-11,0,11), Arrays.asList(-11,1,10), Arrays.asList(-11,2,9), Arrays.asList(-11,3,8), Arrays.asList(-11,4,7), Arrays.asList(-11,5,6), Arrays.asList(-10,-4,14), Arrays.asList(-10,-3,13), Arrays.asList(-10,-2,12), Arrays.asList(-10,-1,11), Arrays.asList(-10,0,10), Arrays.asList(-10,1,9), Arrays.asList(-10,2,8), Arrays.asList(-10,3,7), Arrays.asList(-10,4,6), Arrays.asList(-10,5,5), Arrays.asList(-9,-5,14), Arrays.asList(-9,-4,13), Arrays.asList(-9,-3,12), Arrays.asList(-9,-2,11), Arrays.asList(-9,-1,10), Arrays.asList(-9,0,9), Arrays.asList(-9,1,8), Arrays.asList(-9,2,7), Arrays.asList(-9,3,6), Arrays.asList(-9,4,5), Arrays.asList(-8,-6,14), Arrays.asList(-8,-5,13), Arrays.asList(-8,-4,12), Arrays.asList(-8,-3,11), Arrays.asList(-8,-2,10), Arrays.asList(-8,-1,9), Arrays.asList(-8,0,8), Arrays.asList(-8,1,7), Arrays.asList(-8,2,6), Arrays.asList(-8,3,5), Arrays.asList(-8,4,4), Arrays.asList(-7,-6,13), Arrays.asList(-7,-5,12), Arrays.asList(-7,-4,11), Arrays.asList(-7,-3,10), Arrays.asList(-7,-2,9), Arrays.asList(-7,-1,8), Arrays.asList(-7,0,7), Arrays.asList(-7,1,6), Arrays.asList(-7,2,5), Arrays.asList(-7,3,4), Arrays.asList(-6,-6,12), Arrays.asList(-6,-5,11), Arrays.asList(-6,-4,10), Arrays.asList(-6,-3,9), Arrays.asList(-6,-2,8), Arrays.asList(-6,-1,7), Arrays.asList(-6,0,6), Arrays.asList(-6,1,5), Arrays.asList(-6,2,4), Arrays.asList(-6,3,3), Arrays.asList(-5,-5,10), Arrays.asList(-5,-4,9), Arrays.asList(-5,-3,8), Arrays.asList(-5,-2,7), Arrays.asList(-5,-1,6), Arrays.asList(-5,0,5), Arrays.asList(-5,1,4), Arrays.asList(-5,2,3), Arrays.asList(-4,-4,8), Arrays.asList(-4,-3,7), Arrays.asList(-4,-2,6), Arrays.asList(-4,-1,5), Arrays.asList(-4,0,4), Arrays.asList(-4,1,3), Arrays.asList(-3,-3,6), Arrays.asList(-3,-2,5), Arrays.asList(-3,-1,4), Arrays.asList(-3,0,3), Arrays.asList(-3,1,2), Arrays.asList(-2,-2,4), Arrays.asList(-2,-1,3), Arrays.asList(-2,0,2), Arrays.asList(-2,1,1), Arrays.asList(-1,-1,2), Arrays.asList(-1,0,1)),new int[]{-13,10,11,-3,8,11,-4,8,12,-13,5,-6,-4,-2,12,11,7,-7,-3,10,12,13,-3,-2,6,-1,14,7,-13,8,14,-10,-4,10,-6,11,-2,-3,4,-13,0,-14,-3,3,-9,-6,-9,13,-6,3,1,-9,-6,13,-4,-15,-11,-12,7,-9,3,-2,-12,6,-15,-10,2,-2,-6,13,1,9,14,5,-11,-10,14,-5,11,-6,6,-3,-8,-15,-13,-4,7,13,-1,-9,11,-13,-4,-15,9,-4,12,-4,1,-9,-5,9,8,-14,-1,4,14});
		test(s, Arrays.asList(Arrays.asList(0,0,0)), new int[]{0,0,0});
		test(s, Arrays.asList(Arrays.asList(0,0,0),Arrays.asList(-2,0,2),Arrays.asList(-1,0,1)), new int[]{-2,-1,0,0,0,1,2});
		test(s, Arrays.asList(Arrays.asList(0,0,0),Arrays.asList(-2,0,2),Arrays.asList(-1,0,1)), new int[]{-2,-1,0,0,0,0,1,2});
		test(s, Arrays.asList(Arrays.asList(0,0,0),Arrays.asList(-2,0,2),Arrays.asList(-1,0,1)), new int[]{-2,-1,0,0,0,0,0,1,2});
		test(s, Arrays.asList(Arrays.asList(0,0,0)), new int[]{-100, -99, -98, 0,0,0,0,0,1,2,3});
		test(s, new ArrayList<List<Integer>>(), new int[]{0,0,1,2,3});
		
//		System.out.println(s.threeSum(Utils.createIntArray1D("-5 3 2 -6 4 2 -8 -9 1")));
	}

	private void test(Solution s, List<List<Integer>> expected, int[] input) {
		Comparator<List<Integer>> c = new Comparator<List<Integer>>() {
			@Override
			public int compare(List<Integer> o1, List<Integer> o2) {
				for (int j = 0; j < 3; j++) {
					int n1 = o1.get(j);
					int n2 = o2.get(j);
					int res = n1 - n2;
					if (res != 0) {
						return res;
					}
				}
				return 0;
			}
		};
		List<List<Integer>> actual = s.threeSum(input);
		Collections.sort(actual, c);
		Collections.sort(expected, c);
		Assert.assertEquals(expected, actual);
	}
}